<?php

namespace app\index\model;

use think\Model;

class Shot extends Model
{

    protected $hidden = ['scene_id'];

    public function Scene()
    {
        return $this->belongsTo('Scene', 'scene_id');
    }

    public static function get_shot_id()
    {
        $get_id = Project::get_project_id();
        $get_pip_id=Pipeline::get_pipeline_id($get_id) ;
        $get_sen_id = Scene::get_sen_id($get_pip_id) ;

        $get_sht_id=self::where(['shot_num'=>input('shot_num'),'scene_id' =>$get_sen_id['id']])->field('id')->find() ;
        if (isset($get_sht_id['id'])){
            return [1 ,array('shot_id' => $get_sht_id['id'], )];
            }else{
            return [0 , "not found"];
        } 
    }

    public static function get_data($data='')
    {
        return self::where($data)->order('shot_num')->select();
    }

    public static function get_count($data='')
    {
        return self::where($data)->count();
    }

    public static function add_data()
    {
        $data_count = self::get_count(['shot_num'=>input('shot_num'),'scene_id'=>input('scene_id')]);
        if(!$data_count){
            $data =input() ;
            return [1 , self::strict(false)->insert($data)];
        }else{
            return [0 , "data is repeat"];
        }
    }

    public static function update_data($data)
    {
        return self::update($data);
    }

     public static function delete_data($data='')
    {
        return self::where($data)->delete();
    }
}